//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "TEditBrushForm.h"
#include "TGraphForm.h"
#include "TMainForm.h"
#include "TAreaEditor.h"
#include "TTextEditForm.h"
#include "TEditPointForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TEditBrushForm *EditBrushForm;
//---------------------------------------------------------------------------
__fastcall TEditBrushForm::TEditBrushForm(TComponent* Owner)
	: TForm(Owner)
{
  Brush = new TBrush;
  CurBrush = new TBrush;
}

//---------------------------------------------------------------------------
void TEditBrushForm::SetCurBrush(TBrush *_Brush)
{
  CurBrush = _Brush;
  Brush->Assign(_Brush);
  DefineBrushStyle();
}

//---------------------------------------------------------------------------
void TEditBrushForm::PreviewBrush()
{
  Image->Canvas->Pen->Color = clBtnFace;
  Image->Canvas->Pen->Width = 1;
  Image->Canvas->Pen->Style = psSolid;
  Image->Canvas->Brush->Color = clBtnFace;
  Image->Canvas->Rectangle(0, 0, Image->Width, Image->Height);
  Image->Canvas->Pen->Width = 1;
  Image->Canvas->Pen->Color = 1;
  Image->Canvas->Brush = Brush;
  Image->Canvas->Pen->Style = psSolid;
  Image->Canvas->Rectangle(4, 4, Image->Width-4, Image->Height-4);
}

//---------------------------------------------------------------------------
void __fastcall TEditBrushForm::ComboBoxSelect(TObject *Sender)
{
  Brush->Style = ComboBox->ItemIndex;
  PreviewBrush();
  Changed.Style = true;
}

//---------------------------------------------------------------------------
void __fastcall TEditBrushForm::ChangeClBntClick(TObject *Sender)
{
  MainForm->ColorDialog->Color = Brush->Color;
  MainForm->ColorDialog->Execute();
  Brush->Color = MainForm->ColorDialog->Color;
  PreviewBrush();
  Changed.Color = true;
}

//---------------------------------------------------------------------------
void __fastcall TEditBrushForm::OKBtnClick(TObject *Sender)
{
  if (Changed.Style)
    CurBrush->Style = Brush->Style;
  if (Changed.Color)
    CurBrush->Color = Brush->Color;
  Close();
}

//---------------------------------------------------------------------------
void __fastcall TEditBrushForm::CancelBtnClick(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------
void __fastcall TEditBrushForm::FormShow(TObject *Sender)
{
  Changed.Style = false;
  Changed.Color = false;
  PreviewBrush();
}
//---------------------------------------------------------------------------
void __fastcall TEditBrushForm::DefineBrushStyle()
{
  ComboBox->ItemIndex = Brush->Style;
  Changed.Style = true;
}

void __fastcall TEditBrushForm::HelpBtnClick(TObject *Sender)
{
  Application->HelpContext(4);        
}
//---------------------------------------------------------------------------

